package com.lagou.cluster;

import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

/**
 * @author HuangWei
 */
public class JedisClusterTest {

    @Test
    public void addData() throws IOException {

        Set<HostAndPort> nodes = new HashSet<>();
        nodes.add(new HostAndPort("192.168.80.102", 7001));
        nodes.add(new HostAndPort("192.168.80.102", 7002));
        nodes.add(new HostAndPort("192.168.80.102", 7003));
        nodes.add(new HostAndPort("192.168.80.102", 7004));
        nodes.add(new HostAndPort("192.168.80.102", 7005));
        nodes.add(new HostAndPort("192.168.80.102", 7006));

        JedisCluster jedisCluster = new JedisCluster(nodes);

        String str1 = jedisCluster.set("name:1", "lagou.com");
        System.out.println("添加数据：" + str1);
        String str2 = jedisCluster.get("name:1");
        System.out.println("取出数据：" + str2);

        jedisCluster.close();
    }

}
